package com.example.tys.myfmod;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.tys.fmod.AudioHandle;
import com.tys.fmod.Fmod;

import java.io.File;

public class VoiceActivity extends AppCompatActivity {


    private static final String PATH = Environment.getExternalStorageDirectory()+"/02.mp3";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_voice);


    }

    public void voiceFix(View view) {
        File f = new File(PATH);
        Log.i("----", f.getAbsolutePath() +" _" + f.exists());
        Fmod.supportsLowLatency();
        if(!f.exists()){
            Toast.makeText(view.getContext(), "文件不存在", Toast.LENGTH_SHORT).show();
            return;
        }
        switch (view.getId()) {
            case R.id.gg:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                       AudioHandle.playSound(PATH, AudioHandle.MODE_GAOGUAI);
                    }
                }).start();
                break;
            case R.id.ds:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        AudioHandle.playSound(PATH, AudioHandle.MODE_DASHU);
                    }
                }).start();
                break;
            case R.id.ll:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        AudioHandle.playSound(PATH, AudioHandle.MODE_LUOLI);
                    }
                }).start();
                break;
            case R.id.kl:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        AudioHandle.playSound(PATH, AudioHandle.MODE_KONGLING);
                    }
                }).start();
                break;
            case R.id.js:
                AudioHandle.record();
                break;
            case R.id.ys:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        AudioHandle.playSound(PATH, AudioHandle.MODE_NORMAL);
                    }
                }).start();
                break;
        }
    }

}
